import http from './index'

/// ```
/// 标签部分
/// ```

// 获取标签列表
export const getNoteTags = async () => {
  let res = await http.get('/system/note/list')
  let arr = []
  res.data.rows.map((i) => {
    arr.push({ id: i.id, name: i.noteName, number: null })
  })
  return arr
}

// 获取单个标签 笔记数量
export const NoteSummaryByTag = async (tagName) => {
  let res = await filter(tagName, {
    pageNumber: 1,
    pageSize: 0
  })
  return res.data.total
}

// 通过单个标签过滤笔记
const filter = async (tagName = '', params = {}) => {
  let res = await http.get(`/system/noteitem/list`, {
    params: {
      noteClassify: tagName,
      ...params
    }
  })
  return res
}

/// ```
/// 笔记部分
/// ```

// 创建笔记
export const create_note = async (data) => {
  let res = await http.post('/system/noteitem', data)
  return res.data
}

export const modify_note = async (data) => {
  let res = await http.put('/system/noteitem', data)
  return res.data
}

// 获取笔记列表
export const getNoteList = async (params) => {
  let res = await filter('', params)
  return {
    rows: res.data.rows,
    total: res.data.total
  }
}

// 通过id获取笔记
export const getNoteById = async (id) => {
  let res = await http.get(`/system/noteitem/${id}`)
  return res.data.data
}

// 删除笔记
export const delete_note = async (id) => {
  let res = await http.delete(`/system/noteitem/${id}`)
  return res.data
}

export const setNoteStatus = async (id, status) => {
  let res = await http.put(`/system/noteitem`, {
    id,
    status
  })
  return res.data
}
